// ====================================================================================
// MAIN

/* 
Params passed to this script:
object action was attached to
unit that activated action
index of action
*/

private ["_isAdmin","_player","_name","_index"];
_player = _this select 0;			 
_name = _this select 1;	
_index = _this select 2;


if (player != _player) exitWith { };

if (CFG_AdminCmds == 1) then {
	if (isnil "RMM_ui_teleportbase_init") then {
		RMM_ui_teleportbase_init = {
			[] spawn {
				RMM_ui_teleportbase = [[],objNull];
				_all_players = [];
				if (IsMultiplayer) then {
					_all_players = playableUnits;
				} else {
					_all_players = [player];
				};
				_players = [];
				{
					_add = false;
					if (isplayer _x) then {
						_add = true;
						// if (!isnil "MSO_R_Member" && _x != player) then {
							// if (!((getPlayerUID _x) in MSO_R_Member)) then {
								// _add = true;
							// };
						// } else {
							// _add = true;
						// };
						_jailed = _x getVariable "IS_PLAYER_JAILED";
						if (isnil "_jailed") then { _jailed = false; };
						if (_jailed) then {
							_add = false;
						};
					};
					if (_add) then {
						if (vehicle _x != _x) then {
							if (driver (vehicle _x) == _x) then {
								lbAdd [1101,Format["%1: %2 (%3) in %4 (%5  %6km/h)",localize "STR_DLG_DRIVEVEC", name _x, getPlayerUID _x, typeof (vehicle _x),str(vehicle _x),speed(vehicle _x)]];
							} else {
								lbAdd [1101,Format["%1: %2 (%3) in %4 (%5 %6km/h)",localize "STR_DLG_INVEC", name _x, getPlayerUID _x, typeof (vehicle _x),str(vehicle _x),speed(vehicle _x)]];
							};
						} else {
							lbAdd [1101,Format["%1: %2 (%3)",str _x, name _x, getPlayerUID _x]];
						};
						_players set [count _players, _x];
					};
				} foreach _all_players;
				RMM_ui_teleportbase = [_players,objNull];
			};
		};
	};
	if (isnil "RMM_ui_teleportbase_teleport") then {
		RMM_ui_teleportbase_teleport = {
			private ["_player"];
			_player = (RMM_ui_teleportbase select 1);
			if ((vehicle _player != _player) && (driver (vehicle _player) == _player) && isEngineOn(vehicle _player)) exitWith {
				hint localize "STR_CANNOT_TELEPORT_DRIVER";
			};
			["admin_teleportplayer",[_player,player]] call FNC_ADMINACTIONS_RAISE_EVENT;
		};
	};

	_isAdmin = serverCommandAvailable "#kick" || !isMultiplayer;
	
	if (_isAdmin || CFG_TeamAdmin || CFG_TeamModerator || CFG_TeamMember) then {
		_dialog = createDialog "RMM_ui_teleportbase";
	}else {
		hint localize "STR_CMD_NA";
	};	
};
// ====================================================================================